package com.chglovewxy.gulimall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class GulimallCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter() {
        //1.配置源的实现类,用它调用注册的方法
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

        //3、添加跨域配置
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
//        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.addAllowedOriginPattern("*");
        corsConfiguration.setAllowCredentials(true);

        //2.注册跨域配置到指定访问路径(路径,跨域配置)
        source.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsWebFilter(source);
        
        //4.注意应该注释掉renren-fast的跨域配置,防止冲突.以后都交给我们网关来做
    }
}
